﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using easyVal.ServerSide;

namespace easyVal.ValidationAttributes
{
    public class MilitaryTimeAttribute : ValidationAttribute, IClientValidationMethod
    {
        #region IClientValidationMethod Members

        public string ClientMethodName
        {
            get { return "militaryTime"; }
        }

        public string ClientParameters
        {
            get { return null; }
        }

        #endregion

        public override bool IsValid(object value)
        {
            if (ValidationAttributeUtil.IsDefaultValue(value))
                return true;

            const string strRegex = @"^([0-1][0-9]|[2][0-3])(:)*([0-5][0-9])$";
            return Regex.IsMatch(value.ToString(), strRegex);
        }
    }
}